package com.xuz.factory.factory_method.controller;

import com.xuz.factory.factory_method.factory.FreeGoodsFactoryMap;
import com.xuz.factory.factory_method.factory.impl.DiscountFreeGoodsFactory;
import com.xuz.factory.factory_method.factory.FreeGoodsFactory;
import com.xuz.factory.factory_method.factory.impl.SmallGiftFreeGoodsFactory;
import com.xuz.factory.simple_factory.entity.AwardInfo;
import com.xuz.factory.simple_factory.entity.ResponseResult;

import com.xuz.factory.simple_factory.service.IFreeGoods;

/**
 * 发放奖品接口
 *
 * @user 65453
 * @date 2024/9/24 21:51
 */
public class DeliverController {

    /**
     * 按照类型的不同发放商品
     */
    public ResponseResult awardToUser(AwardInfo awardInfo) {
        // 根据类型获取具体工厂
        FreeGoodsFactory freeGoodsFactory = FreeGoodsFactoryMap.getParserFactory(awardInfo.getAwardType());

        // 从工厂类中获取对应实例
        IFreeGoods freeGoods = freeGoodsFactory.getInstance();

        System.out.println("=====工厂方法模式========");
        ResponseResult result = freeGoods.sendFreeGoods(awardInfo);

        return result;
    }

}
